package com.jikangjun.disk.quoteinfo.service.impl;

import com.jikangjun.disk.mybatis.flexigrid.PagingEntity;
import com.jikangjun.disk.mybatis.flexigrid.TblResponseEntity;
import com.jikangjun.disk.quoteinfo.entity.SearchReceivedShareEntity;
import com.jikangjun.disk.quoteinfo.entity.ReceivedShareEntity;
import com.jikangjun.disk.quoteinfo.repository.QuoteinfoDao;
import com.jikangjun.disk.quoteinfo.service.QuoteinfoService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 收到分享服务实现类
 */
@Service
public class QuoteinfoServiceImpl implements QuoteinfoService {
    
    @Resource
    private QuoteinfoDao quoteinfoDao;
    
    @Override
    public TblResponseEntity<ReceivedShareEntity> queryReceivedShareListByPage(SearchReceivedShareEntity entity, PagingEntity paging) {
        TblResponseEntity<ReceivedShareEntity> tblResponseEntity = new TblResponseEntity<>();
        Integer total = quoteinfoDao.queryReceivedShareListTotal(entity);
        tblResponseEntity.setTotal(total);
        
        paging.deal(ReceivedShareEntity.class, total);
        tblResponseEntity.setPage(paging.getPage());
        List<ReceivedShareEntity> list = quoteinfoDao.queryReceivedShareListByPage(entity, paging);
        tblResponseEntity.setRawRecords(list);
        
        tblResponseEntity.deal();
        return tblResponseEntity;
    }
    
    @Override
    public ReceivedShareEntity queryReceivedShareById(String shareId) {
        return quoteinfoDao.queryReceivedShareById(shareId);
    }
    
    @Override
    public void acceptShare(String shareId) {
        quoteinfoDao.updateReceivedShareStatus(shareId, 1);
    }
    
    @Override
    public void acceptShareBatch(String[] shareIds) {
        for (String shareId : shareIds) {
            quoteinfoDao.updateReceivedShareStatus(shareId, 1);
        }
    }
    
    @Override
    public void rejectShare(String shareId) {
        quoteinfoDao.updateReceivedShareStatus(shareId, 2);
    }
    
    @Override
    public void rejectShareBatch(String[] shareIds) {
        for (String shareId : shareIds) {
            quoteinfoDao.updateReceivedShareStatus(shareId, 2);
        }
    }
    
    @Override
    public void updateViewCount(String shareId) {
        quoteinfoDao.updateViewCount(shareId);
    }
} 